package com.example.commonmistak.apidesign.controller;

import com.example.commonmistak.apidesign.anno.ApiVersion;
import com.example.commonmistak.apidesign.anno.NoApiResponse;
import com.example.commonmistak.apidesign.common.ApiException;
import com.example.commonmistak.apidesign.common.ExceptionEnum;
import com.example.commonmistak.apidesign.entity.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xionggg
 * @date 2022/2/2 09:40
 */
@RestController
@ApiVersion("v1")
public class DemoController {

    @RequestMapping("demo1")
    public String demo1() {
        return "Hello World! happy new year";
    }

    @RequestMapping("demo2")
    @NoApiResponse
    public String demo2() {
        return "Hello World! happy new year";
    }

    @RequestMapping("demo3")
    @ApiVersion("v2")
    public User demo3() {
        return User.builder().name("张飒").age(18).build();
    }

    @RequestMapping("demo4")
    public User demo4() {
        throw new ApiException(ExceptionEnum.USER_NOT_EXISTS);
    }
}
